var HOST = "https://wx.himayi.cn/Home/";

function XRKHttpGet(api, succ, fail) {
  var url = HOST + api;
  wx.request({
    url: url,
    method: 'GET',
    success: function (res) {
      console.log(url, res);
      if (res.statusCode == 200) {
        succ(res.data);
      }
      else {
        fail(res.data);
      }
    },
    fail: function (error) {
      console.log(url, error);
      fail(error);
    }
  })
}
function XRKHttpPost(api, para, succ, fail) {
  var url = HOST + api;
  wx.request({
    url: url,
    data: para,
    method: 'POST',
    header: {
      "content-type": "application/x-www-form-urlencoded"
    },
    success: function (res) {
      console.log(url, res);
      if (res.statusCode == 200) {
        succ(res.data);
      }
      else {
        fail(res.data);
      }
    },
    fail: function (error) {
      console.log(url, error);
      fail(error);
    }
  })
}

function Login(para, succ, fail) {
  XRKHttpPost("Index/login", para, succ, fail);
}

function accessToken(para, succ, fail) {
  XRKHttpPost("Index/get_qrcode", para, succ, fail);
}

function getCode(para, succ, fail) {
  XRKHttpPost("Index/access_token", para, succ, fail);
}

function Main(para, succ, fail) {
  XRKHttpPost("Index/main", para, succ, fail);
}

function getPhotoData(para, succ, fail) {
  XRKHttpPost("Index/get_photo_data", para, succ, fail);
}

function getPhotoOne(para, succ, fail) {
  XRKHttpPost("Index/get_photo_one", para, succ, fail);
}

function getPhotoDetail(para, succ, fail) {
  XRKHttpPost("Index/get_photo_detail", para, succ, fail);
}

function delPhoto(para, succ, fail) {
  XRKHttpPost("Index/del_photo", para, succ, fail);
}

function delPhotoImages(para, succ, fail) {
  XRKHttpPost("Index/del_photo_images", para, succ, fail);
}

function setCateName(para, succ, fail) {
  XRKHttpPost("Index/set_cate_name", para, succ, fail);
}

function addCateName(para, succ, fail) {
  XRKHttpPost("Index/add_cate_name", para, succ, fail);
}

function addImages(para, succ, fail) {
  XRKHttpPost("Index/add_images", para, succ, fail);
}

function getCateDetail(para, succ, fail) {
  XRKHttpPost("Index/get_cate_detail", para, succ, fail);
}

function getCateRole(para, succ, fail) {
  XRKHttpPost("Index/get_cate_role", para, succ, fail);
}

function getCateRoleUser(para, succ, fail) {
  XRKHttpPost("Index/get_cate_role_user", para, succ, fail);
}

function getCateRoleTransfer(para, succ, fail) {
  XRKHttpPost("Index/get_cate_role_transfer", para, succ, fail);
}

function setCateRoleUser(para, succ, fail) {
  XRKHttpPost("Index/set_cate_role_user", para, succ, fail);
}

function setCateRoleTransfer(para, succ, fail) {
  XRKHttpPost("Index/set_cate_role_transfer", para, succ, fail);
}

function getCateUserList(para, succ, fail) {
  XRKHttpPost("Index/get_cate_user_list", para, succ, fail);
}

function setCateRole(para, succ, fail) {
  XRKHttpPost("Index/set_cate_role", para, succ, fail);
}

function getUserShow(para, succ, fail) {
  XRKHttpPost("Index/get_user_show", para, succ, fail);
}

function setUserShow(para, succ, fail) {
  XRKHttpPost("Index/set_user_show", para, succ, fail);
}

function setImagesZan(para, succ, fail) {
  XRKHttpPost("Index/set_images_zan", para, succ, fail);
}

function showMsgDialog(msg, cb) {
  wx.showModal({
    content: msg,
    showCancel: false,
    success: cb
  })
}
function showLoading(title ='加载中'){
  wx.showLoading({
    "title": title,
    "mask": true
  })
}
function checkAuth(fun) {
  wx.getSetting({
    /*success(res) {
    }*/
    success: fun
  })
}
module.exports = {
  checkAuth: checkAuth,
  Login: Login,
  Main: Main,
  addImages: addImages,
  getPhotoOne: getPhotoOne,
  getPhotoData: getPhotoData,
  getPhotoDetail: getPhotoDetail,
  delPhoto: delPhoto,
  delPhotoImages:delPhotoImages,
  accessToken: accessToken,
  setCateName: setCateName,
  addCateName: addCateName,
  showMsgDialog: showMsgDialog,
  showLoading: showLoading,
  getCateRole: getCateRole,
  setCateRole: setCateRole,
  getUserShow: getUserShow,
  setUserShow: setUserShow,
  getCateRoleUser: getCateRoleUser,
  setCateRoleUser: setCateRoleUser,
  getCateUserList: getCateUserList,
  getCateRoleTransfer: getCateRoleTransfer,
  setCateRoleTransfer: setCateRoleTransfer,
  getCateDetail:getCateDetail,
  setImagesZan: setImagesZan
}